import Vue from 'vue'
import Router from 'vue-router'
import Layout from '../views/layout'
import Login from '../views/login'
import Dashboard from '../views/dashboard'
import Farm from '../views/farm'
import VisiualScreen from '../views/visiualScreen'
import WeatherForcast from '../views/weatherForcast'
import WeatherWarn from '../views/weatherWarn'
import Disasterforecast from '../views/disasterforecast'
import Digitalfarm from '../views/digitalFarm'
import Personmanagel from '../views/personManagel'

import  {checkUser} from '@/services'

Vue.use(Router)

const router=new Router({
  routes:[
    {
      path:'/layout',
      component:Layout,
      children:[
        {
          path:'dash',
          name:'dash',
          component:Dashboard
        },
        {
          path:'screen',
          name:'screen',
          component:VisiualScreen
        },
        {
          path:'weatherforcast',
          name:'weatherforcast',
          component:WeatherForcast
        },
        {
          path:'weatherwarn',
          name:'weatherwarn',
          component:WeatherWarn
        },
        {
          path:'disasterforecast',
          name:'disasterforecast',
          component:Disasterforecast
        },
        {
          path:'farm',
          name:'farm',
          component:Farm
        },
        {
          path:'digitalfarm',
          name:'digitalfarm',
          component:Digitalfarm
        },
        {
          path:'personmanagel',
          name:'personmanagel',
          component:Personmanagel
        }
      ]
    },
    {
      path:'/login',
      component:Login
    },
    {
      path:'*',
      redirect:'/login'
    }
  ]
})

const whitList = ['/login','register']

router.beforeEach((to,from,next)=>{

  if(whitList.includes(to.path)){
    next()
    return
  }
  checkUser(next)
 
})

export default router